/*============================================================================*/
/*  Copyright (C) 2009-2013, iSOFT INFRASTRUCTURE SOFTWARE CO.,LTD.
 *  
 *  All rights reserved. This software is iSOFT property. Duplication 
 *  or disclosure without iSOFT written authorization is prohibited.
 *  
 *  @file       <Fls.h>
 *  @brief      <Flash Driver>
 *  
 *  <Compiler: Tasking MCU:TC1782>
 *  
 *  @author     <Tommy>
 *  @date       <2014-11-7>
 */
/*============================================================================*/

#ifndef FLS_H
#define FLS_H

/*=======[R E V I S I O N   H I S T O R Y]====================================*/
/*  <VERSION>    <DATE>    <AUTHOR>    <REVISION LOG>
 *  V1.0.0       20141107   Tommy      Initial version
 * 
 */
/*============================================================================*/

/*=======[V E R S I O N  I N F O R M A T I O N]===============================*/
#define FLS_MODULE_ID            92U
#define FLS_H_VENDOR_ID          62U
#define FLS_H_AR_MAJOR_VERSION   2U
#define FLS_H_AR_MINOR_VERSION   2U
#define FLS_H_AR_PATCH_VERSION   3U
#define FLS_H_SW_MAJOR_VERSION   1U
#define FLS_H_SW_MINOR_VERSION   0U
#define FLS_H_SW_PATCH_VERSION   0U

/*=======[I N C L U D E S]====================================================*/
#include "Std_Types.h"
#include "MemIf_Types.h"
/*=======[M A C R O S]========================================================*/
#define FLS_INSTANCE_ID                   (0U)
#define FLS_SECTOR_PTR(sectorNo)            NULL_PTR
#define FLS_BLOCK_NUMBER      0
/*=======[T Y P E   D E F I N I T I O N S]====================================*/
/** @req FLS216 */
typedef uint32 Fls_AddressType;
typedef uint32 Fls_LengthType;

typedef P2FUNC(Std_ReturnType,FLS_APPL_CODE,Fls_EraseFct)
(
    Fls_AddressType TargetAddress,
    uint32 sectorNo
);

typedef P2FUNC(Std_ReturnType,FLS_APPL_CODE,Fls_WriteFct)
(
    Fls_LengthType SectorAddr,
    Fls_LengthType PageAddr,
    P2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) WriteDataPtr,
    Fls_LengthType PageSize,
    uint32 sectorNo
);

typedef P2FUNC(void, FLS_APPL_CODE, FlsJobNotificationFct)(void);

/* define FLS module initiation status */
typedef enum
{
    FLS_JOB_NONE = 0u,
    FLS_JOB_ERASE,
    FLS_JOB_WRITE,
    FLS_JOB_READ,
    FLS_JOB_COMPARE
}Fls_RequestJobType;

typedef enum
{
    FLS_EARSE_AC = 0u,
    FLS_WRITE_AC,
    FLS_AC_COUNT
}Fls_LoadACType;


/* Configuration description of a flashable sector */
typedef struct 
{
    /* Number of continuous sectors with the above characteristics. */

    /*Size of one page of this sector. Implementation Type: Fls_LengthType.*/
    Fls_LengthType FlsPageSize; /** @req FLS281 */

    /* Size of this sector. Implementation Type: Fls_LengthTyp */
    Fls_LengthType FlsSectorSize; /** @req FLS282 */

    /* Start address of sectors */
    Fls_AddressType FlsSectorStartaddress; /** @req FLS283 */

    /* End address of sectors */
    Fls_AddressType FlsSectorEndaddress;

    /* The higher 16bits: Flash Type, The lower 16bits: SectorNo */
    uint32 FlsSecotrNo;

} Fls_SectorType;/** @req FLS202 */


typedef struct
{
    #if STD_ON == FLS_AC_LOAD_ON_JOB_START
    /*Function pointer for Erase access code*/
    Fls_EraseFct FlsACErasePtr;/** @req FLS270 */

    /*Function pointer for Write access code*/
    Fls_WriteFct FlsACWritePtr;/** @req FLS271 */
    #endif
    #if STD_ON == FLS_DEV_ERROR_DETECT
    /* Cycle time of calls of the flash driver's main function */
    uint32 FlsCallCycle;/** @req FLS272 */
    #endif

    /*Maximum number of bytes to Read in one cycle of FLS driver job processing in Fast Mode*/
    Fls_LengthType FlsMaxReadFastMode;/** @req FLS275 */

    /*Maximum number of bytes to Read in one cycle of FLS driver job processing in Normal Mode*/
    Fls_LengthType FlsMaxReadNormalMode;/** @req FLS276 */

    /*Maximum number of bytes to Write in one cycle of FLS driver job processing in Fast Mode*/
    Fls_LengthType FlsMaxWriteFastMode;/** @req FLS277 */

    /*Maximum number of bytes to Write in one cycle of FLS driver job processing in Normal Mode*/
    Fls_LengthType FlsMaxWriteNormalMode;/** @req FLS278 */

    /*Wait state configuration for Read access and error correction*/
    uint8 FlsWaitStates;

    P2CONST(Fls_SectorType,AUTOMATIC,FLS_APPL_DATA)  FlsSector;
    
    uint8 FlsBlockNum;

}Fls_ConfigType;

/*=======[E X T E R N A L   F U N C T I O N   D E C L A R A T I O N S]========*/

/*************************************************************************/
/*
 * Brief               Erases flash sector(s).
 * ServiceId           0x1 
 * Sync/Async          Asynchronous
 * Reentrancy          Non Reentrant
 * Param-Name[in]      TargetAddress: address offset
 *                     Length:Number of bytes to erase
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              None
 * PreCondition        None
 * CallByAPI           Up layer(FEE)
 */
/*************************************************************************/
extern FUNC(Std_ReturnType, FLS_CODE)
Fls_Erase(Fls_AddressType TargetAddress,Fls_LengthType Length);

/*************************************************************************/
/*
 * Brief               Writes one or more complete flash pages.
 * ServiceId           0x2 
 * Sync/Async          Asynchronous
 * Reentrancy          Non Reentrant
 * Param-Name[in]      TargetAddress: address offset
 *                     SourceAddressPtr:Pointer to source data buffer
 *                     Length:Number of bytes to write
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              None
 * PreCondition        None
 * CallByAPI           Up layer(FEE)
 */
/*************************************************************************/
extern FUNC(Std_ReturnType, FLS_CODE)
Fls_Write
(
    Fls_AddressType TargetAddress,
    P2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) SourceAddressPtr,
    Fls_LengthType Length
);


/*************************************************************************/
/*
 * Brief               return the result of the last job synchronously.
 * ServiceId           0x5 
 * Sync/Async          Synchronous
 * Reentrancy          Reentrant
 * Param-Name[in]      void
 * Param-Name[out]     None
 * Param-Name[in/out]  None
 * Return              MemIf_JobResultType
 * PreCondition        None
 * CallByAPI           Up layer
 */
/*************************************************************************/
extern FUNC(MemIf_JobResultType, FLS_CODE)
Fls_GetJobResult(void);

#endif/* #ifndef _FLS_H */
/*=======[E N D   O F   F I L E]==============================================*/
